<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<%@ taglib prefix="his_fns" uri="/WEB-INF/tlds/his_fns.tld" %>
<script>
    //包床
    $('#btnSubmit').click(function(){
        var patientId = "${bedRec.patientId}";
        var visitId = "${bedRec.visitId}";
        var visitNo = "${visitNo}";
        if(visitNo==null||visitNo==''){
            toastr.error('请先选择住院病人');
        }else{
            var ids =[];
            $('input[name="notInBed"]:checked').each(function(){
                ids.push($(this).val());
            });
            if(ids.length==0){
                toastr.error('请先选择可包床位');
            }else{
                $.ajax({
                    type: "POST",
                    url: "${ctx}/nurse/bedRec/saveInBed?ids="+ids+'&bedOccupy='+visitNo+"&patientId="+patientId+"&visitId="+visitId,
                    dataType: "json",
                    success: function (data) {
                        toastr.success(data.data);
                        loadDiv('bedOccupyRight','${ctx}/nurse/bedRec/bedOccupyRight?visitNo='+visitNo);
                        //loadDiv('mainCenterDiv','${ctx}/nurse/bedRec/bedOccupyList?visitNo='+visitNo)
                    },
                    error: function (data) {
                        toastr.error('网络连接错误,请检查网络');
                    }
                });
            }
        }
    });
    function bedCancel(id){
        $("#id").val(id) ;
    }
    //解除包床
    $('#btnCancel').click(function(){
        var visitNo = "${visitNo}";
        var id = $("#id").val();
        var ids =[id];
        if(id==null||id==""){
            toastr.error('请先选择已包床位');
        }else{
            $.ajax({
                type: "POST",
                url: "${ctx}/nurse/bedRec/saveInBed?ids="+ids+'&bedOccupy=0',
                dataType: "json",
                success: function (data) {
                    toastr.success(data.data);
                    loadDiv('bedOccupyRight','${ctx}/nurse/bedRec/bedOccupyRight?visitNo='+visitNo);
                    //loadDiv('mainCenterDiv','${ctx}/nurse/bedRec/bedOccupyList?visitNo='+visitNo)
                },
                error: function (data) {
                    toastr.error('网络连接错误,请检查网络');
                }
            });
        }
    })

</script>
<section class="panel" style="height: 50%">
  <header class="panel-heading">已包床位</header>
  <div class="panel-body">
    <div class="table-responsive no-border">
      <table id="contentTable" class="table table-bordered mg-t datatable">
        <thead>
        <tr>
          <th>床号</th>
          <th>床标号</th>
          <th>房间</th>
          <th>男/女</th>
          <th>等级</th>
          <th>空调等级</th>
          <th>类型</th>
          <th>空床</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${inBedRecsVisitNo}" var="inBedRecsVisitNo">
          <tr onclick="bedCancel('${inBedRecsVisitNo.id}')">
            <td>${inBedRecsVisitNo.bedNo}</td>
            <td>${inBedRecsVisitNo.bedLabel}</td>
            <td>${inBedRecsVisitNo.roomNo}</td>
            <td>${fns:getDictLabel(inBedRecsVisitNo.bedSexType,"SEX_DICT" ,"" )}</td>
            <td>${his_fns:getClinicName(inBedRecsVisitNo.bedGrade)}</td>
            <td>${his_fns:getClinicName(inBedRecsVisitNo.airconditionClass)}</td>
            <td>${fns:getDictLabel(inBedRecsVisitNo.bedApprovedType,"BED_APPROVED_TYPE_DICT" ,"" )}</td>
            <td>${fns:getDictLabel(inBedRecsVisitNo.bedStatus,"YES_NO" ,"" )}</td>
          </tr>
        </c:forEach>
        </tbody>
      </table>
    </div>
  </div>
</section>
<section class="panel" style="height: 50%">
  <header class="panel-heading">可供包床的空床位</header>
  <div class="panel-body">
    <div class="table-responsive no-border">
      <table id="contentTable1" class="table table-bordered mg-t datatable">
        <thead>
        <tr>
          <th><input type="checkbox" id="checkedall" ></th>
          <th>床号</th>
          <th>床标号</th>
          <th>房间</th>
          <th>男/女</th>
          <th>等级</th>
          <th>空调等级</th>
          <th>类型</th>
          <th>空床</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${notInBedList}" var="notInBed">
          <tr>
            <td align="center"><input type="checkbox" name="notInBed" value="${notInBed.id}"></td>
            <td>${notInBed.bedNo}</td>
            <td>${notInBed.bedLabel}</td>
            <td>${notInBed.roomNo}</td>
            <td>${fns:getDictLabel(notInBed.bedSexType,"SEX_DICT" ,"" )}</td>
            <td>${his_fns:getClinicName(notInBed.bedGrade)}</td>
            <td>${his_fns:getClinicName(notInBed.airconditionClass)}</td>
            <td>${fns:getDictLabel(notInBed.bedApprovedType,"BED_APPROVED_TYPE_DICT" ,"" )}</td>
            <td>${fns:getDictLabel(notInBed.bedStatus,"YES_NO" ,"" )}</td>
          </tr>
        </c:forEach>
        </tbody>
      </table>
    </div>
  </div>
</section>
<div class="form-group">
  <div class="col-sm-offset-2 col-sm-10">
    <input type="hidden" id="id" value="">
    <input id="btnSubmit" class="btn btn-primary" type="button" value="包 床">&nbsp;
    <input id="btnCancel" class="btn" type="button" value="解除包床">
  </div>
</div>